<?php
/**
 * Created by PhpStorm.
 * User: hao03
 * Date: 2019/3/4
 * Time: 21:21
 */

namespace app\common\model;
use think\Model;

class PeccancyLog extends Model
{
    protected $name = 'peccancy_log';

    public function getUserPecLogList($where, $filed, $limit, $request, $keyword) {

        if ($keyword) {
            $data = $this->alias('pl')
                ->join('car_auth ca', 'pl.user_id = ca.user_id', 'left')
                ->field($filed)
                ->where($where)
//                ->whereOr('pl.user_id', $keyword)
//                ->whereOr('ca.name', $keyword)
//                ->whereOr('pl.id', $keyword)
//                ->whereOr('ca.phone', $keyword)
                ->whereOr('pl.user_id|ca.name|pl.id|ua.phone','like',"%$keyword%")
                ->order('pl.create_time desc')
                ->paginate($limit, false, ['query' => $request->get()]);
        } else {
            $data = $this->alias('pl')
                ->join('car_auth ca', 'pl.user_id = ca.user_id', 'left')
                ->field($filed)
                ->where($where)
                ->order('pl.create_time desc')
                ->paginate($limit, false, ['query' => $request->get()]);
        }

        return $data;
    }

    public function getUserPecLogDetail($where, $filed){

        $detail = $this
            ->alias('pl')
            ->join('car_auth ca', 'pl.user_id = ca.user_id', 'left')
            ->join('user_auth ua', 'pl.user_id = ua.user_id', 'left')
            ->field($filed)
            ->where($where)
            ->field($filed)
            ->find();

        return $detail;
    }
}